package tuan.score;

import org.w3c.dom.Node;

import tuan.utils.StringUtil;

public class PureLengthScore extends LengthScore {
	public PureLengthScore(int length, String op, double score)
			throws Exception {
		super(length, op, score);
	}

	protected int getTextLen(Node node) {
		return StringUtil.getPureText(node.getTextContent().replaceAll("[0-9]", "")).length();
	}

	@Override
	protected double getScore(Node node) {
		double defaultScore = 0.0;
		int textLen = getTextLen(node);

		if (op.equals(">")) {
			return textLen > length ? score : defaultScore;
		}
		if (op.equals(">=")) {
			return textLen >= length ? score : defaultScore;
		}
		if (op.equals("<")) {
			return textLen < length ? score : defaultScore;
		}
		if (op.equals("<=")) {
			return textLen <= length ? score : defaultScore;
		}
		if (op.equals("!=")) {
			return textLen != length ? score : defaultScore;
		}
		return defaultScore;
	}

}
